#!/bin/bash

clear
echo "EXECUTING INIT ..."


if [[ -f /etc/lab/lab-functions ]]; then
    . /etc/lab/lab-functions
fi

if [[ -f /etc/lab/lab.conf ]]; then
    . /etc/lab/lab.conf
else
    echo "No appliance config file found ... Dropping to shell"
    /bin/bash
    exit 0
fi

mkdir -p /{dev,proc,sys,etc,var,lib,lib64,tmp,usr,root,mnt}
mkdir -p /dev/{shm,pts}
mkdir -p /var/{log,run,lib,lock,db,spool,opt,empty,www}
mkdir -p /var/lock/subsys
mkdir -p /var/run/netreport
mkdir -p /var/lib/{rpm,dhclient}
mkdir -p /home/admin
mkdir -p /usr/share

echo "Mounting proc, sysfs"
mount -t proc proc /proc
mount -t sysfs sys /sys
mount -t tmpfs tmpfs /dev/shm
mount -t devpts -o gid=5,mode=620 devpts /dev/pts

# Install stuff
if [[ $INSTALL_TYPE == "LIVE" ]]; then
    echo "Running Live System"
elif [[ $INSTALL_TYPE == "INSTALL" ]]; then
    echo "The entire system is available on the disk"
    echo "Find root partition"
    echo "Mount root"
fi

# More encryption stuff here

if [[ `grep debug /proc/cmdline` ]]; then 
    echo "Debug mode ... Dropping to shell"
    /bin/bash
fi

# Run the regular init
exec /sbin/init
